#include "Config.h"

Config::Config() {
	CurrentArea = 0;
	CurrentID = 0;

    RenderMode = USE_DEFAULT_RASTERIZER;
	FlyCamera = false;
	DisplayStats = true;
	FrameCapped = false;
	Target_FPS = 15;

	CameraMovementSpeed = 5.0f;
	CameraMovementSpeedSprint = 10.0f;
	CameraRotationSpeed = 0.1f;
	CameraInitialPosition = XMVectorSet(0.0f, 1.0f, -5.0f, 0.0f);
	CameraInitialTarget = XMVectorSet(0.0f, 1.0f, -4.0f, 0.0f);
	CameraInitialUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	CurrentTexture  = "default.jpg";
	DefaultTexture  = "default.jpg";
    CurrentMaterial = "default.jpg";
	DefaultMaterial = "default.jpg";

    PathToAreas    = "Areas/";
    PathToAudio    = "Audio/";
	PathToTextures = "Textures/";

    Textures.push_back("default.jpg");
    Textures.push_back("error.png");
}

void Config::ToggleRenderMode() {
	RenderMode = !RenderMode;
}

void Config::ToggleFlyCamera() {
	FlyCamera = !FlyCamera;
}

void Config::ToggleDisplayStats() {
	DisplayStats = !DisplayStats;
}

void Config::ToggleFrameCapped() {
	FrameCapped = !FrameCapped;
}

void Config::IncreaseTargetFPS() {
	if (Target_FPS < 120)
		Target_FPS += 5;
}

void Config::DecreaseTargetFPS() {
	if (Target_FPS > 5)
		Target_FPS -= 5;
}

string Config::GetTexture(int textureNumber) {
	return Textures.at(textureNumber);
}

int Config::GetTextureNumber(string textureName) {
    if(textureName.compare("") == 0) {
        return 0;
    }
	for(UINT i=0; i<Textures.size(); i++) {
        if(Textures.at(i).compare(textureName) == 0) {
            return (int)i;
        }
    }
    //texture can't be found, return error texture a.k.a. texture #1
    return 1;
}

boolean Config::ExistsTexture(string textureName) {
    for(UINT i=0; i<(UINT)Textures.size(); i++) {
        if(Textures.at(i).compare(textureName) == 0) {
            return true;
        }
    }
    return false;
}

void Config::AddTexture(string textureName) {
	if(!ExistsTexture(textureName)) {
		Textures.push_back(textureName);
	}
}

void Config::RemoveTexture(string textureName) {
	for(UINT i=0; i<Textures.size(); i++) {
        if(Textures.at(i).compare(textureName) == 0) {
            Textures.erase(Textures.begin() + i);
        }
    }
    assert(false); //cannot find texture with name textureName
}

void Config::RemoveTexture(int textureNumber) {
	Textures.erase(Textures.begin() + textureNumber);
}

string Config::GetCurrentTexture() {
	return CurrentTexture;
}

boolean Config::SetCurrentTexture(string textureName) {
	if(ExistsTexture(textureName)) {
		CurrentTexture = textureName;
		return true;
	}
	return false;
}

string Config::GetDefaultTexture() {
	return DefaultTexture;
}

boolean Config::SetDefaultTexture(string textureName) {
	if(ExistsTexture(textureName)) {
		DefaultTexture = textureName;
		return true;
	}
	return false;
}

boolean existsIn(string s, vector<string>* strings) {
	for(UINT i=0; i<strings->size(); i++) {
		if(strings->at(i).compare(s) == 0) {
			return true;
		}
	}
	return false;
}

int Config::GetNrOfTextures() {
	return Textures.size();
}

string Config::GetMaterial(int materialNumber) {
	return Materials.at((UINT)materialNumber);
}

int Config::GetMaterial(string materialName) {
    for(UINT i=0; i<Materials.size(); i++) {
        if(Materials.at(i).compare(materialName) == 0) {
            return (int)i;
        }
    }
    assert(false); //cannot find texture with name textureName
    return -1;
}

boolean Config::ExistsMaterial(string materialName) {
    for(UINT i=0; i<Materials.size(); i++) {
        if(Materials.at(i).compare(materialName) == 0) {
            return true;
        }
    }
    return false;
}

void Config::AddMaterial(string materialName) {
    Materials.push_back(materialName);
}

void Config::RemoveMaterial(string materialName) {
    for(UINT i=0; i<Materials.size(); i++) {
        if(Materials.at(i).compare(materialName) == 0) {
            Materials.erase(Materials.begin() + i);
        }
    }
}

void Config::RemoveMaterial(int materialNumber) {
	Materials.erase(Materials.begin() + materialNumber);
}

string Config::GetCurrentMaterial() {
	return CurrentMaterial;
}

boolean Config::SetCurrentMaterial(string materialName) {
	if(ExistsMaterial(materialName)) {
		CurrentMaterial = materialName;
		return true;
	}
	return false;
}

string Config::GetDefaultMaterial() {
	return DefaultMaterial;
}

boolean Config::SetDefaultMaterial(string materialName) {
	if(ExistsMaterial(materialName)) {
		DefaultMaterial = materialName;
		return true;
	}
	return false;
}

int Config::GetNrOfMaterials() {
	return (int)(Materials.size());
}

int Config::GetNewID() {
	return ++CurrentID;
}